<?php   // $Id: table_create.php 315 2008-11-02 13:56:22Z pcoustillas $ ?>
<?php
/*
Copyright (C) 2003-2004 Guy Hendrickx
Licensed under the terms of the GNU  General Public License:http://www.opensource.org/licenses/gpl-license.php
File Authors:Guy Hendrickx
Modification : Pierre Coustillas
*/

require_once("../include/config/common.php");
$msg_erreur="Erreur lors de la création des tables. Vérifier que le nom de la base est correct ($db) ";

//$tblpref="test";

// si les tables existent dejà ont les supprimes avant de les recréer
$sql = "DROP TABLE ${tblpref}article";
mysql_query($sql);
$sql = "DROP TABLE ${tblpref}bon_comm";
mysql_query($sql);
$sql = "DROP TABLE ${tblpref}client";
mysql_query($sql);
$sql = "DROP TABLE ${tblpref}categorie";
mysql_query($sql);
$sql = "DROP TABLE ${tblpref}cont_bon";
mysql_query($sql);
$sql = "DROP TABLE ${tblpref}depense";
mysql_query($sql);
$sql = "DROP TABLE ${tblpref}facture";
mysql_query($sql);
$sql = "DROP TABLE ${tblpref}user";
mysql_query($sql);
$sql = "DROP TABLE ${tblpref}cont_dev";
mysql_query($sql);
$sql = "DROP TABLE ${tblpref}devis";
mysql_query($sql);
$sql = "DROP TABLE ${tblpref}cont_lot";
mysql_query($sql);
$sql = "DROP TABLE ${tblpref}lot";
mysql_query($sql);
$sql = "DROP TABLE ${tblpref}coordonnees";
mysql_query($sql);

// ------------------------------------------------------------
// ------------------------- DEVIS --------------------------
$sql_devis = "CREATE TABLE {$tblpref}devis ( num_dev int( 30 ) NOT NULL AUTO_INCREMENT ,
		client_num 	varchar( 10 ) 	NOT NULL default '',
		date 			date 				NOT NULL default '0000-00-00',
		tot_htva 	float( 20, 2 ) NOT NULL default '0.00',
		tot_tva 		float( 20, 2 ) NOT NULL default '0.00',
		resu 			varchar( 4 ) 	NOT NULL default '0',
		coment 		varchar( 200 ) NOT NULL default '',
		reference	varchar( 80 ) 	NOT NULL default '',
		PRIMARY KEY ( num_dev ) ) TYPE = MYISAM";

mysql_query($sql_devis)or die("$msg_erreur <br/> $sql_devis <br/>" . mysql_error());

// ------------------------------------------------------------
// ------------------------- CONT_DEV --------------------------
$sql_cont_dev = "CREATE TABLE ${tblpref}cont_dev( num int( 30 ) NOT NULL AUTO_INCREMENT ,
		dev_num 		varchar( 30 ) 	NOT NULL default '',
		article_num int( 10 ) 		NOT NULL default '0',
		quanti 		double 			NOT NULL default '0',
		tot_art_htva float( 20, 2) NOT NULL default '0.00',
		to_tva_art 	float( 20, 2 ) NOT NULL default '0.00',
		PRIMARY KEY ( num ) ) TYPE = MYISAM";

mysql_query($sql_cont_dev) or die ("$msg_erreur <br/> $sql_cont_dev <br/> " . mysql_error());

// ------------------------------------------------------------
// ------------------------- BON_COMM --------------------------
$sql_bon_comm = "CREATE TABLE ${tblpref}bon_comm ( num_bon int( 30 ) NOT NULL AUTO_INCREMENT ,
		client_num 	varchar( 10 ) 	NOT NULL default '',
		date 			date 				NOT NULL default '0000-00-00',
		tot_htva 	float( 20, 2 ) NOT NULL default '0.00',
		tot_tva 		float( 20, 2 ) NOT NULL default '0.00',
		num_facture int( 6 ) 		NOT NULL default '0',
		coment 		varchar( 200 ) NOT NULL default '',
		reference	varchar( 80 ) 	NOT NULL default '',
		PRIMARY KEY ( num_bon ) ) TYPE = MYISAM ";

mysql_query($sql_bon_comm)or die("$msg_erreur <br/> $sql_bon_comm <br/> " . mysql_error());

// ------------------------------------------------------------
// ------------------------- CONT_BON --------------------------
$sql_cont_bon = "CREATE TABLE ${tblpref}cont_bon( num int( 30 ) NOT NULL AUTO_INCREMENT ,
		bon_num 		varchar( 30 ) 	NOT NULL default '',
		num_lot 		int(10)		 	NOT NULL default '0',
		article_num int( 10 ) 		NOT NULL default '0',
		quanti 		double 			NOT NULL default '0',
		tot_art_htva float(20,2) 	NOT NULL default '0.00',
		to_tva_art 	float( 20, 2 ) NOT NULL default '0.00',
		PRIMARY KEY ( num ) ) TYPE = MYISAM";

mysql_query($sql_cont_bon) or die ("$msg_erreur <br/> $sql_cont_bon <br/>" . mysql_error());

// ------------------------------------------------------------
// ------------------------- FACTURE --------------------------
$sql_facture = "CREATE TABLE ${tblpref}facture( num int( 11 ) NOT NULL ,
		client 		varchar( 40 ) 	NOT NULL default '',
		payement 	varchar( 15 ) 	NOT NULL default 'non',
		date_fact 	date 				NOT NULL default '0000-00-00',
		total_fact_h float(20,2) 	NOT NULL default '0.00',
		total_fact_ttc float(20,2) NOT NULL default '0.00',
		nb_relance 	tinyint( 4 ) 	NOT NULL default '0',
		coment 		varchar( 200 ) NOT NULL default '',
		acompte 		float( 10, 2 ) NOT NULL default '0.00',
		valide 		tinyint( 4 ) 	NOT NULL default '0',
		reference	varchar( 80 ) 	NOT NULL default '',
		PRIMARY KEY ( num ) ) TYPE = MYISAM";

mysql_query($sql_facture)or die ("$msg_erreur <br/> $sql_facture <br/> " . mysql_error());


// ------------------------------------------------------------
// ------------------------- ARTICLE --------------------------
$sql_article = "CREATE TABLE ${tblpref}article ( num int( 10 ) NOT NULL AUTO_INCREMENT ,
		article 		varchar( 70 ) 	NOT NULL default '0',
		prix_htva 	float	 	NOT NULL default '0.00',
		taux_tva 	float(5,2) 					default '0.00',
		commentaire varchar( 30 ) 	NOT NULL default '0',
		uni 			varchar( 5 ) 	NOT NULL default '',
		actif 		varchar( 5 ) 	NOT NULL default '',
		stock 		float(15,2) 	NOT NULL default '0.00',
		stomin 		float(15,2) 	NOT NULL default '0.00',
		stomax 		float(15,2) 	NOT NULL default '0.00',
		cat 			varchar(10) 	NOT NULL default '0',
		PRIMARY KEY ( num ) ) TYPE = MYISAM";

mysql_query($sql_article)or die("$msg_erreur <br/> $sql_article <br/> " . mysql_error());

// ------------------------------------------------------------
// ------------------------- CLIENT --------------------------
$sql_client = "CREATE TABLE ${tblpref}client ( num_client int( 10 ) NOT NULL AUTO_INCREMENT ,
		nom 			varchar( 30 ) 	NOT NULL default '',
		nom2 			varchar( 30 ) 	NOT NULL default '',
		rue 			varchar( 30 ) 	NOT NULL default '',
		ville 		varchar( 30 ) 	NOT NULL default '',
		cp 			varchar( 5 ) 	NOT NULL default '',
		num_tva 		varchar( 30 ) 	NOT NULL default '',
		login 		varchar( 15 ) 	NOT NULL default '',
		pass 			varchar( 40 ) 	NOT NULL default '',
		mail			varchar( 60 ) 	NOT NULL default '',
		actif 		varchar( 5 ) 	NOT NULL default '',
		civ 			varchar(15) 	NOT NULL default '',
		tel 			varchar(30) 	NOT NULL default '',
		fax 			varchar(30) 	NOT NULL default '',
		PRIMARY KEY ( num_client ) ) TYPE = MYISAM";
mysql_query($sql_client) or die ("$msg_erreur <br/>$sql_client <br/>" . mysql_error());

// ------------------------------------------------------------
// ------------------------- CATEGORIE --------------------------
$sql_categorie="CREATE TABLE ${tblpref}categorie (id_cat int(11) NOT NULL auto_increment,
		categorie 	varchar(30) 	NOT NULL default '',
		PRIMARY KEY  (id_cat) ) TYPE=MyISAM";
mysql_query($sql_categorie) or die ("$msg_erreur <br/> $sql_categorie <br/>" . mysql_error());

$sql_cat="INSERT INTO ${tblpref}categorie (id_cat, categorie) VALUES ('0', '---')";
mysql_query($sql_cat) or die ("$msg_erreur <br/>$sql_cat <br/>". mysql_error());

// ------------------------------------------------------------
// ------------------------- DEPENSE --------------------------
$sql_depense = "CREATE TABLE ${tblpref}depense( num int( 11 ) NOT NULL AUTO_INCREMENT ,
		date 			date 				NOT NULL default '0000-00-00',
		lib 			varchar( 50 ) 	NOT NULL default '',
		fournisseur varchar( 30 ) 	NOT NULL default '',
		prix 			float( 10, 2 ) NOT NULL default '0.00',
		PRIMARY KEY ( num ) ) TYPE = MYISAM";

mysql_query($sql_depense) or die ("$msg_erreur <br/> $sql_depense <br/>" . mysql_error());

// ------------------------------------------------------------
// ------------------------- USER --------------------------
$sql_user = "CREATE TABLE ${tblpref}user ( num int( 10 ) NOT NULL AUTO_INCREMENT ,
		login 		varchar( 10 ) 	NOT NULL default '',
		nom 			varchar( 20 ) 	NOT NULL default '',
		prenom 		varchar( 20 ) 	NOT NULL default '',
		pwd 			varchar( 40 )	NOT NULL default '',
		email 		varchar( 60 ) 	NOT NULL default '',
		dev 			char( 1 ) 		NOT NULL default 'n',
		com 			char( 1 ) 		NOT NULL default 'n',
		fact 			char( 1 ) 		NOT NULL default 'n',
		admin 		char( 1 ) 		NOT NULL default 'n',
		dep 			char( 1 ) 		NOT NULL default 'n',
		stat 			char( 1 ) 		NOT NULL default 'n',
		art 			char( 1 ) 		NOT NULL default 'n',
		cli 			char( 1 ) 		NOT NULL default 'n',
		PRIMARY KEY ( num ) ) TYPE = MYISAM";

mysql_query($sql_user)or die ("$msg_erreur <br/> $sql_user <br/>" . mysql_error());

// ------------------------------------------------------------
// ------------------------- LOT --------------------------
$sql_lot = "CREATE TABLE ${tblpref}lot ( num int( 10 ) NOT NULL AUTO_INCREMENT ,
		prod 			varchar( 25 ) 	NOT NULL default '',
		actif 		char(3) 			NOT NULL default '0',
		date 			date 							default '0000-00-00',
		PRIMARY KEY ( num ) ) TYPE = MYISAM";

mysql_query($sql_lot) or die("$msg_erreur <br/> $sql_lot <br/> " . mysql_error());

// ------------------------------------------------------------
// ------------------------- CONT_LOT --------------------------
$sql_cont_lot = "CREATE TABLE {$tblpref}cont_lot ( num int( 15 ) NOT NULL AUTO_INCREMENT ,
		num_lot 		int( 10 ) 		NOT NULL default '0',
		ingr 			varchar(20) 	NOT NULL default '',
		fourn 		varchar(15) 				default '',
		fourn_lot 	varchar( 20 ) 	NOT NULL default '',
		PRIMARY KEY ( num ) ) TYPE = MYISAM";

mysql_query($sql_cont_lot)or die("$msg_erreur <br/> $sql_cont_lot <br/>" . mysql_error());

// ------------------------------------------------------------
// ------------------------- COORDONNEES --------------------------
$sql_coordonnees = "CREATE TABLE {$tblpref}coordonnees ( ligne int( 2 ) NOT NULL,
		col1_nom 	varchar(150) 	NOT NULL default '',
		col1_size 	int(2) 			NOT NULL default '10',
		col1_align 	char(1) 			NOT NULL	default 'R',
		col2_nom 	varchar(150)	NOT NULL default '',
		col2_size 	int(2) 			NOT NULL default '10',
		col2_align 	char(1) 			NOT NULL default 'L',
		PRIMARY KEY ( ligne ) ) TYPE = MYISAM";

mysql_query($sql_coordonnees)or die("$msg_erreur <br/> $sql_coordonnees <br/>" . mysql_error());

//valeur par defauts et création des 8 lignes de la table coordonnees 
$sql_coordonnees = "INSERT INTO {$tblpref}coordonnees (ligne,col1_nom,col2_nom) VALUES 
		(1,'Pour modifier','ces valeurs')";
mysql_query($sql_coordonnees)or die("Erreur insertion donnees <br/> $sql_coordonnees <br/>" . mysql_error());
$sql_coordonnees = "INSERT INTO {$tblpref}coordonnees (ligne,col1_nom,col2_nom) VALUES 
		(2,'Menu Outils','Vos coordonnees')";
mysql_query($sql_coordonnees)or die("Erreur insertion donnees <br/> $sql_coordonnees <br/>" . mysql_error());
$sql_coordonnees = "INSERT INTO {$tblpref}coordonnees (ligne) VALUES (3)";
mysql_query($sql_coordonnees)or die("Erreur insertion donnees <br/> $sql_coordonnees <br/>" . mysql_error());
$sql_coordonnees = "INSERT INTO {$tblpref}coordonnees (ligne) VALUES (4)";
mysql_query($sql_coordonnees)or die("Erreur insertion donnees <br/> $sql_coordonnees <br/>" . mysql_error());
$sql_coordonnees = "INSERT INTO {$tblpref}coordonnees (ligne) VALUES (5)";
mysql_query($sql_coordonnees)or die("Erreur insertion donnees <br/> $sql_coordonnees <br/>" . mysql_error());
$sql_coordonnees = "INSERT INTO {$tblpref}coordonnees (ligne) VALUES (6)";
mysql_query($sql_coordonnees)or die("Erreur insertion donnees <br/> $sql_coordonnees <br/>" . mysql_error());
$sql_coordonnees = "INSERT INTO {$tblpref}coordonnees (ligne) VALUES (7)";
mysql_query($sql_coordonnees)or die("Erreur insertion donnees <br/> $sql_coordonnees <br/>" . mysql_error());
$sql_coordonnees = "INSERT INTO {$tblpref}coordonnees (ligne,col1_size,col1_align) VALUES (8,8,'C')";
mysql_query($sql_coordonnees)or die("Erreur insertion donnees <br/> $sql_coordonnees <br/>" . mysql_error());
$sql_coordonnees = "INSERT INTO {$tblpref}coordonnees (ligne,col1_size,col1_align) VALUES (9,8,'C')";
mysql_query($sql_coordonnees)or die("Erreur insertion donnees <br/> $sql_coordonnees <br/>" . mysql_error());
$sql_coordonnees = "INSERT INTO {$tblpref}coordonnees (ligne,col1_size,col1_align) VALUES (10,8,'C')";
mysql_query($sql_coordonnees)or die("Erreur insertion donnees <br/> $sql_coordonnees <br/>" . mysql_error());


?>
